<?php
//导购会员接收数据页面
require_once("../includes/public.inc.php");
$s = isset($_GET['s'])?$_GET['s']:'';
$act = isset($_GET['act'])?$_GET['act']:'';//也是type
$openid = isset($_GET['openid'])?$_GET['openid']:'';
if ($act=='dg')
{
	$user = isset($_POST['user'])?$_POST['user']:'';
	$username = isset($_POST['userName'])?$_POST['userName']:'';
	$sex = isset($_POST['rdoSex'])?$_POST['rdoSex']:'';
	$password = isset($_POST['password'])?$_POST['password']:'';
	$shop_name = isset($_POST['shopname'])? $_POST['shopname']:'';
	$address = isset($_POST['shangjiadizhi'])?$_POST['shangjiadizhi']:'';
	$job = isset($_POST['job'])?$_POST['job']:'';
	$province = isset($_POST['province'])?$_POST['province']:'';
	$city = isset($_POST['city'])?$_POST['city']:'';
}
else 
{
	$user = isset($_POST['user'])?$_POST['user']:'';
	$username = isset($_POST['userName'])?$_POST['userName']:'';
	$sex = isset($_POST['rdoSex'])?$_POST['rdoSex']:'';
	$password = isset($_POST['password'])?$_POST['password']:'';
	$address = isset($_POST['address'])?$_POST['address']:'';
	$province = isset($_POST['province'])?$_POST['province']:'';
	$city = isset($_POST['city'])?$_POST['city']:'';
}
if ($user&&$username&&$password)
{
	//echo "select * from " .DBQIAN. "daogou where username='".trim($user)."' or openid='".$openid."'";exit;
	$select_dg = mysql_fetch_array(mysql_query("select * from " .DBQIAN. "daogou where username='".trim($user)."' or wx_openid='".$openid."'"));
	$select_hy = mysql_fetch_array(mysql_query("select * from " .DBQIAN. "users where username='".$user."' or openid='".$openid."'"));
	if ($select_dg)
	{
		echo "<script>alert('注册失败!你已经是导购，需要找回密码，请联系管理员');history.go(-1);</script>";exit;
	}
	else 
	{
		if($select_hy)
		{
			echo "<script>alert('注册失败!已存在该用户，需要找回密码，请联系管理员');history.go(-1);</script>";exit;
		}
	}
	if ($act == 'dg')
	{
//		echo "insert into ".DBQIAN."daogou(username,name,password,shopname,province,city,shopaddress,job,last_login,create_time,wx_user,wx_openid,status) values('".$user."','".$username."','".$password."','".$shopname."','".$province."','".$city."','".$address."',".$job.",'".time()."','".date('Y-m-d H:i:s',time())."','','".$openid."',0)";exit;
		$add = mysql_query("insert into ".DBQIAN."daogou(username,name,password,shopname,province,city,shopaddress,job,last_login,create_time,wx_user,wx_openid,status,sex) values('".$user."','".$username."','".$password."','".$shopname."','".$province."','".$city."','".$address."',".$job.",'".time()."','".date('Y-m-d H:i:s',time())."','','".$openid."',0,'".$sex."')");
		if ($add)
		{
			$_SESSION['username'] = $user;
			$_SESSION['password'] = $password;
//			$exsit_fwm = mysql_fetch_array(mysql_query("select * from ".DBQIAN."fwm where fwm='".$s."' and zt=0 order by id desc limit 1"));
//			if ($exsit_fwm)
//			{
//				header("Location: linghongbao.php?s=".$s);exit;
//			}
//			else 
//			{
//				header("Location: index.php?s=".$s."&type=dg");exit;
//			}
			header("Location: check.php?s=".$s."&type=dg");exit;//注册成功后直接跳到审核页面
		}
		else 
		{
			echo "<script>alert('注册失败!');history.go(-1);</script>";exit;
		}
	}
	else 
	{
		//需要修改，完成
		//echo "insert into ".DBQIAN."users(username,name,password,sex,province,city,address,credit,last_login,createtime,openid) values('".$user."','".$username."','".$password."','".$sex."','".$province."','".$city."','".$address."',0,'".time()."','".date('Y-m-d H:i:s',time())."','".$openid."')";exit;
		$add = mysql_query("insert into ".DBQIAN."users(username,name,password,sex,province,city,address,credit,last_login,createtime,openid) values('".$user."','".$username."','".$password."','".$sex."','".$province."','".$city."','".$address."',0,'".time()."','".date('Y-m-d H:i:s',time())."','".$openid."')");
		if ($add)
		{
			$_SESSION['username'] = $user;
			$_SESSION['password'] = $password;
			if ($s)
			{
				$exsit_fwm = mysql_fetch_array(mysql_query("select * from ".DBQIAN."fwm where fwm='".$s."' and hystatus=0 order by id desc limit 1"));
			}
			if ($exsit_fwm)//没查过，领积分
			{
				header("Location: jifen.php?s=".$s."&type=hy");exit;
			}
			else 
			{
				header("Location: index.php?s=".$s."&type=hy");exit;
			}
		}
		else 
		{
			echo "<script>alert('注册失败!');history.go(-1);</script>";exit;
		}
	}
}
else 
{
	echo "<script>alert('请正确填写你的信息!');history.go(-1);</script>";exit;
}